﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ClassLibraryForMusic;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex != -1)
            {
                Album.AbstractMusicFile musFile = new ClassLibraryForMusic.Album.ClassicMusicFile(0, "", "", new List<string>());
                ClassLibraryForMusic.FactoryClassForMusicFiles.ICreator creator = new FactoryClassForMusicFiles.ClassicMusicFileCreator();
                if (comboBox1.SelectedItem.ToString() == "Классическая")
                    creator = new FactoryClassForMusicFiles.ClassicMusicFileCreator();
                if (comboBox1.SelectedItem.ToString() == "Рок")
                    creator = new FactoryClassForMusicFiles.RockMusicFileCreator();
                if (comboBox1.SelectedItem.ToString() == "Альтернативный рок")
                    creator = new FactoryClassForMusicFiles.AlternativeRockMusicFileCreator();
                musFile = creator.FactoryMethod_CreateMusicFile();
                musFile.Length = (int)numericUpDown1.Value;
                musFile.Name_of_File = textBoxName.Text;
                musFile.Author = textBoxAuthor.Text;
                if (comboBox1.SelectedItem.ToString() == "Классическая")
                {
                    Album.ClassicMusicFile classic = (Album.ClassicMusicFile)musFile;
                    for (int i = 0; i < listBoxOrchestraInstruments.Items.Count; i++)
                        classic.OrchestraInstruments.Add(listBoxOrchestraInstruments.Items[i].ToString());
                }
                else
                {
                    Album.RockMusicFile rock = (Album.RockMusicFile)musFile;
                    for (int i = 0; i < listBoxRockers.Items.Count; i++)
                        rock.Rockers.Add(listBoxRockers.Items[i].ToString());
                    for (int i = 0; i < listBoxRockInstruments.Items.Count; i++)
                        rock.RockInstruments.Add(listBoxRockInstruments.Items[i].ToString());
                    if (comboBox1.SelectedItem.ToString() == "Альтернативный рок")
                    {
                        Album.AlternativeRockMusicFile al = (Album.AlternativeRockMusicFile)musFile;
                        al.TypeOfAlternativeRock = Album.AlternativeRockMusicFile.TypesOfAlternativeRock.Unknown;
                        if (comboBoxAlterType.SelectedItem.ToString() == "Usual")
                            al.TypeOfAlternativeRock = Album.AlternativeRockMusicFile.TypesOfAlternativeRock.Usual;
                        if (comboBoxAlterType.SelectedItem.ToString() == "Unknown")
                            al.TypeOfAlternativeRock = Album.AlternativeRockMusicFile.TypesOfAlternativeRock.Unknown;
                        if (comboBoxAlterType.SelectedItem.ToString() == "DeathMetalRock")
                            al.TypeOfAlternativeRock = Album.AlternativeRockMusicFile.TypesOfAlternativeRock.DeathAlternative;
                        if (comboBoxAlterType.SelectedItem.ToString() == "Anoth")
                            al.TypeOfAlternativeRock = Album.AlternativeRockMusicFile.TypesOfAlternativeRock.AnothAlternative;
                    }
                }
                Form1.Альбом.Add_MusicFile(musFile);
                Close();
            }
            else
                MessageBox.Show("Необходимо определить тип композиции.");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            groupBoxClassic.Visible = false;
            groupBoxRock.Visible = false;
            labelAlterType.Visible = false;
            comboBoxAlterType.Visible = false;
            if (comboBox1.SelectedItem.ToString() == "Классическая")
                groupBoxClassic.Visible = true;
            else
            {
                groupBoxRock.Visible = true;
                if (comboBox1.SelectedItem.ToString() == "Альтернативный рок")
                {
                    labelAlterType.Visible = true;
                    comboBoxAlterType.Visible = true;
                }
            }
        }

        private void buttonAddOrchestraInstruments_Click(object sender, EventArgs e)
        {
            Form form = new Form();
            TextBox text = new TextBox();
            text.Parent = form;
            form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            form.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.AutoSize = true;
            text.KeyDown += (object _sender, KeyEventArgs _e) =>
            {
                if (_e.KeyCode == Keys.Enter)
                {
                    listBoxOrchestraInstruments.Items.Add(text.Text);
                    form.Close();
                }
            };
            form.ShowDialog();
        }

        private void buttonAddRockInstruments_Click(object sender, EventArgs e)
        {
            Form form = new Form();
            TextBox text = new TextBox();
            text.Parent = form;
            form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            form.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.AutoSize = true;
            text.KeyDown += (object _sender, KeyEventArgs _e) =>
            {
                if (_e.KeyCode == Keys.Enter)
                {
                    listBoxRockInstruments.Items.Add(text.Text);
                    form.Close();
                }
            };
            form.ShowDialog();
        }

        private void buttonAddRockers_Click(object sender, EventArgs e)
        {
            Form form = new Form();
            TextBox text = new TextBox();
            text.Parent = form;
            form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            form.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.AutoSize = true;
            text.KeyDown += (object _sender, KeyEventArgs _e) =>
            {
                if (_e.KeyCode == Keys.Enter)
                {
                    listBoxRockers.Items.Add(text.Text);
                    form.Close();
                }
            };
            form.ShowDialog();
        }
    }
}
